var code=getQueryVariable("code");
var ym=getQueryVariable("ym");
var codes=code.split(",");
var obj="";
for(var i=0;i<codes.length;i++){
    obj=obj+"&"+codes[i];
}
obj=obj.replaceAll(":","=");
//ym=ym+"##"+obj;

var reporturl=getReportUrl();
//reporturl="http://localhost:6001/quiee/reportJsp/showReport.jsp?raq=/";

//var objs=ym.split("##");
var url="";

    url=reporturl+ym+".raq"+obj;


$("#reporturl")[0].src=url;
$("#searchs").click(function(){

  //  alert("搜索")
    var code=$("#code")[0].value;
    var type=$("#type")[0].value;
    var usercode=$("#salesman")[0].value

    if(usercode==undefined){
        usercode="RKB008";
    }


    url=reporturl+ym+".raq"+"&code="+code+"&type="+type+"&usercode="+usercode;
    $("#reporturl")[0].src=url;//"http://127.0.0.1:6001/quiee/reportJsp/showReport.jsp?raq=/customerCount.raq&code=&type=9&usercode=RKB009";\\
    initable22();
});

var fls=getdictionary(6,27);//客户类型
//下拉列表重新赋值
setselecttype(fls,"type");
//查询条件中类型
initable22();
function setselecttype(dt,key) {
    var options="";
    for(var i=0;i<dt.length;i++){
        options+="<option value='"+dt[i].code+"'>"+dt[i].name+"</option>";
    }
    $("#"+key+"").append(options);

}
let salesmanCodes="";//所属 业务员下拉框选择值
function getAllJson(jsons) {
    let tmpitem=[]
    for (let item of jsons) {
        let tmparr={}
        tmparr["value"]=item["code"];
        tmparr["name"]=item["name"];
        if(item["users"]){
            for(let it of item["users"]){
                item["list"].push(it)
            }
        }
        if(item["list"] && item["list"].length){
            tmparr["children"]=   this.getAllJson(item["list"]);
            tmpitem.push(tmparr)
        }else{
            tmpitem.push(tmparr)
        }

    }
    return tmpitem
}
function getxmselect(el,name, data) {
    return xmSelect.render({
        el: el,
        name: name,
        tree: {
            show: true,
            showLine: true,
            showFolderIcon:true,
            indent: 20,
            expandedKeys:false
        },
        height: 'auto',
        data: data,
        on: function ({ arr, change, isAdd }) {
            //return this
            salesmanCodes="";
            for(var i=0;i<change.length;i++){
                if(i == change.length-1){
                    salesmanCodes=salesmanCodes+ change[i].value;
                }else{
                    salesmanCodes=salesmanCodes+ change[i].value+",";
                }
            }

        }
    })
}
function initable22() {
//获取当前用户的部门及人员结构树
    let treeList = getCurrentDepartmentUser();
    if(treeList && treeList.list){
        let userTree = getAllJson(treeList.list);
        //getxmselect("#operationCode","owneroperator", userTree);
        salesmanCodes= getxmselect("#salesman","subordinatesalesman", userTree);
    }else {
        //  getxmselect("#operationCode","owneroperator", [{name: user.name, value: user.code}]);
        salesmanCodes= getxmselect("#salesman","subordinatesalesman", [{name: user.name, value: user.code}]);
    }
}

//获取字典
function getdictionary(dl,xl) {
    var obj=[];
    $.ajax({
        type : 'POST',
        //  url : 'resource/getTree',
        data: {"type":dl,"lx":xl},
        url:'dictionary2/getValues',
        dataType:"json",
        // contentType: 'application/json',
        async:false,
        success : function (da) {
            if(da.status==200 ){
                obj=da.data;
            }
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });
    return obj;
}
//获取报表url前缀
function  getReportUrl() {
    var url=getdictionary(6,54);
    return url[1].name;
}
